#include "SDLVisualObject.h"

SDLVisualObject::SDLVisualObject(SDL_Surface *target):
	screen(target)
{
}

SDLVisualObject::~SDLVisualObject(void)
{
}

void SDLVisualObject::loadImage(std::string filename)
{
	mode = VMO_IMAGE;

	SDL_Surface* original = IMG_Load(filename.c_str());

	if(original == 0)
		throw std::string("Cannot load image file ") + filename;

	SDL_Surface* optimized = SDL_DisplayFormatAlpha(original);
	SDL_FreeSurface(original);
	
	me = optimized;
}

int SDLVisualObject::getWidth()
{
	return me->w;

}

int SDLVisualObject::getHeight()
{
	return me->h;

}

void SDLVisualObject::draw()
{
	SDL_Rect offset;
	offset.x = offsetX;
	offset.y = offsetY;

	SDL_BlitSurface(me, 0, screen, &offset);

}